import 'package:flutter/material.dart';
import 'TabBarWidget.dart';
import 'PageFirst.dart';

class PageWidget extends StatefulWidget {
  final String title;

  const PageWidget({Key key, this.title}) : super(key: key);

  @override
  _PageWidget createState() => _PageWidget(title);
}

class _PageWidget extends State<PageWidget> {
  final String _title;

  _PageWidget(this._title);

  @override
  Widget build(BuildContext context) {
    return new TabBarWidget(
        type: TabBarWidget.TOP_TAB,
        tabItems: _renderTab(),
        tabViews: _renderPage(),
        pageController: topPageControl,
        backgroundColor: Colors.lightBlue,
        indicatorColor: Colors.redAccent,
        title: new Text(_title));
  }

  final PageController topPageControl = new PageController();

  final List<String> tab = ["111", "222", "333", "444", "555", "666", "777"];

  _renderTab() {
    List<Widget> list = new List();
    for (int i = 0; i < tab.length; i++) {
      list.add(new FlatButton(
          onPressed: () {
            topPageControl.jumpTo(MediaQuery.of(context).size.width * i);
          },
          child: new Text(
            tab[i],
            maxLines: 1,
          )));
    }
    return list;
  }

  _renderPage() {
    return [
      new PageFirst(),
      new PageFirst(),
      new PageFirst(),
      new PageFirst(),
      new PageFirst(),
      new PageFirst(),
      new PageFirst(),
    ];
  }
}
